<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\EnrollTeacher;
use App\User;
class AddUserOpenidToEnroll extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'add:user_openid_to_enroll';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '同步招生老师openid';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $enrollTeachers = EnrollTeacher::get();
        foreach($enrollTeachers as $enroll){
            $user = User::where('mobile',$enroll->mobile)->select('openid')->first();
            if($user && $user->openid){
                $enroll->openid = $user->openid;
                $enroll->save();
            }
        }
    }
}